package com.menu.web.controller.cases;

import com.menu.common.annotation.Log;
import com.menu.common.core.controller.BaseController;
import com.menu.common.core.domain.AjaxResult;
import com.menu.common.core.page.TableDataInfo;
import com.menu.common.enums.BusinessType;
import com.menu.common.utils.poi.ExcelUtil;
import com.menu.system.domain.MenuCase;
import com.menu.system.service.IMenuCaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 案例分享Controller
 *
 * @author ruoyi
 * @date 2024-07-10
 */
@RestController
@RequestMapping("/system/case")
public class MenuCaseController extends BaseController {
    @Autowired
    private IMenuCaseService menuCaseService;

    /**
     * 查询案例分享列表
     */
    @PreAuthorize("@ss.hasPermi('system:case:list')")
    @GetMapping("/list")
    public TableDataInfo list(MenuCase menuCase) {
        startPage();
        List<MenuCase> list = menuCaseService.selectMenuCaseList(menuCase);
        return getDataTable(list);
    }

    /**
     * 导出案例分享列表
     */
    @PreAuthorize("@ss.hasPermi('system:case:export')")
    @Log(title = "案例分享", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MenuCase menuCase) {
        List<MenuCase> list = menuCaseService.selectMenuCaseList(menuCase);
        ExcelUtil<MenuCase> util = new ExcelUtil<MenuCase>(MenuCase.class);
        util.exportExcel(response, list, "案例分享数据");
    }

    /**
     * 获取案例分享详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:case:query')")
    @GetMapping(value = "/{caseId}")
    public AjaxResult getInfo(@PathVariable("caseId") Long caseId) {
        return success(menuCaseService.selectMenuCaseByCaseId(caseId));
    }

    /**
     * 新增案例分享
     */
    @PreAuthorize("@ss.hasPermi('system:case:add')")
    @Log(title = "案例分享", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MenuCase menuCase) {
        return toAjax(menuCaseService.insertMenuCase(menuCase));
    }

    /**
     * 修改案例分享
     */
    @PreAuthorize("@ss.hasPermi('system:case:edit')")
    @Log(title = "案例分享", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MenuCase menuCase) {
        return toAjax(menuCaseService.updateMenuCase(menuCase));
    }

    /**
     * 删除案例分享
     */
    @PreAuthorize("@ss.hasPermi('system:case:remove')")
    @Log(title = "案例分享", businessType = BusinessType.DELETE)
    @DeleteMapping("/{caseIds}")
    public AjaxResult remove(@PathVariable Long[] caseIds) {
        return toAjax(menuCaseService.deleteMenuCaseByCaseIds(caseIds));
    }
}
